<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <h2>基地址</h2>
    <button class="btn1">get</button>
    <button class="btn2">post</button>
    
    <script src="./axios.js"></script>
    <script>
      axios.defaults.baseURL = 'http://ajax-api.itheima.net'
      document.querySelector('.btn1').onclick = function () {
        axios({
          url: '/api/news',
          method: 'get',
        }).then((res) => {
          console.log('res:', res)
        })
      }
      document.querySelector('.btn2').onclick = function () {
        axios({
          url: '/api/login',
          method: 'post',
          data: {
            username: 'admin',
            password: '123456',
          },
        }).then((res) => {
          console.log('res:', res)
        })
      }
    </script>
  </body>
</html>